/* 封装文章接口 */

import axios from '@/utils/request'

/**
 * 获取文章列表数据
 *
 * @export
 * @param {*} id  频道ID
 * @param {*} timestamp 时间戳
 * @return {*}
 */
export function getArticle(id, timestamp) {
  return axios({
    url: '/v1_0/articles',
    // get 方式，数据写在params中
    params: {
      channel_id: id,
      timestamp
    }
  })
}

/**
 *对文章不喜欢(不感兴趣)
 *
 * @export
 * @param {*} target 不喜欢的文章id
 * @return {*}
 */
export function disLikeArt(target) {
  return axios({
    url: '/v1_0/article/dislikes',
    method: 'post',
    data: {
      target
    }
  })
}

/**
 *举报文章
 *
 * @export
 * @param {*} target 文章id
 * @param {*} type   举报类型
 * @return {*}
 */
export function reportArt(target, type) {
  return axios({
    url: '/v1_0/article/reports',
    method: 'POST',
    data: {
      target,
      type
    }
  })
}

/**
 *获取新闻详情
 *
 * @export
 * @param {*} id 文章id
 * @return {*}
 */
export function getArticleInfo(id) {
  return axios({
    url: `/v1_0/articles/${id}`
  })
}

/**
 *关注作者
 *
 * @export
 * @param {*} target 关注的用户id
 * @return {*}
 */
export function addFollowUser(target) {
  return axios({
    url: '/v1_0/user/followings',
    method: 'POST',
    data: {
      target
    }
  })
}

/**
 * 取消关注作者
 *
 * @export
 * @param {*} target 关注的用户id
 * @return {*}
 */
export function unFollowUser(target) {
  return axios({
    url: `/v1_0/user/followings/${target}`,
    method: 'DELETE'
  })
}

/**
 * 取消点赞
 * @param {*} id 文章编号
 */
export const deleteLike = id => {
  return axios({
    method: 'delete',
    url: '/v1_0/article/likings/' + id
  })
}

/**
 * 添加点赞
 * @param {*} id 文章编号
 */
export const addLike = id => {
  return axios({
    method: 'post',
    url: '/v1_0/article/likings',
    data: {
      target: id
    }
  })
}

/**
 * 取消不喜欢
 * @param {*} id 文章编号
 */
export const deleteDisLike = id => {
  return axios({
    method: 'delete',
    url: '/v1_0/article/dislikes/' + id
  })
}

/**
 * 添加不喜欢
 * @param {*} id 文章编号
 */
export const addDisLike = id => {
  return axios({
    method: 'post',
    url: '/v1_0/article/dislikes',
    data: {
      target: id
    }
  })
}

/**
 * 获取文章的评论数据
 * @param {*} source 文章id
 * @param {*} offset 偏移量
 * @returns
 */
export function getArticleCommon(source, offset) {
  return axios({
    url: '/v1_0/comments',
    params: {
      type: 'a',
      source,
      offset,
      // 每页10条数据
      limit: 10
    }
  })
}

/**
 * 获取评论的回复评论数据
 * @param {*} source 评论id
 * @param {*} offset 偏移量
 * @returns
 */
export function getCommonToCommon(source, offset) {
  return axios({
    url: '/v1_0/comments',
    params: {
      type: 'c',
      source,
      offset,
      // 每页10条数据
      limit: 10
    }
  })
}

/**
 * 对文章进行评论
 * @param {*} target 文章id
 * @param {*} content 评论内容
 * @returns
 */
export function addCommon(target, content) {
  return axios({
    url: '/v1_0/comments',
    method: 'POST',
    data: {
      target,
      content
    }
  })
}

/**
 * 对评论进行回复评论
 * @param {*} artId 所属文章id
 * @param {*} target 评论id
 * @param {*} content 评论内容
 * @returns
 */
export function addCommonToCommon(artId, target, content) {
  return axios({
    url: '/v1_0/comments',
    method: 'POST',
    data: {
      art_id: artId,
      target,
      content
    }
  })
}

/**
 * 对评论进行点赞
 * @param {*} target 评论id
 * @returns
 */
export function addCommonLike(target) {
  return axios({
    url: '/v1_0/comment/likings',
    method: 'POST',
    data: {
      target
    }
  })
}

/**
 * 对评论进行取消点赞
 * @param {*} target 评论id
 * @returns
 */
export function removeCommonLike(target) {
  return axios({
    url: `/v1_0/comment/likings/${target}`,
    method: 'DELETE'
  })
}
